<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../static/bm/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../static/bm/css/thesame.css" media="all">
    <link rel="stylesheet" href="../static/bm/bmuserinfo/css/rightCon.css" media="all">
    <link rel="stylesheet" href="../static/bm/bmuserinfo/css/page.css" media="all">
</head>

<script>
    var isCURD = false;
</script>
<shiro:hasPermission name="huodongshiguanli_cud">
    <script>
        isCURD = true;
    </script>
</shiro:hasPermission>

<body class="layui-layout-body">
<div class="layui-body ">
    <!-- 内容主体区域 -->
    <div class="bgWhite box-shadows1 border-radius4 scroll-box">
        <div class="scroll-box-con border-radius4 bgWhite">
            <div class="border-bot1px pb20px mb20px">
                <div class="add-mess">
                    <div class="add-mess-child left">
                        <div>
                            <label>关键字：</label>
                        </div>
                        <div class="add-mess-form">
                            <p class="add-mess-form-tree"><input type="text" autocomplete="off" id="param" placeholder="请输入活动室名称、联系人姓名" style="width:100%" class="bgWhite"></p>
                        </div>

                    </div>
                    <div class="left">
                        <span class="white border-radius4 bgGreen block pl20px pr20px ml30px lh34px cursor" id="serchBtn">查&nbsp;询</span>
                    </div>
                </div>
            </div>
            <div class="mb20px lh32px overflow add-btn-input">
                <p class="left cursor">
                    <shiro:hasPermission name="huodongshiguanli_cud">
                    <span class="white border-radius4 bgGreen inline-block pl15px pr15px" onclick="toAdd()">
                        <img src="../static/bm/bmuserinfo/img/button_add.png">新建
                    </span>
                    </shiro:hasPermission>
                </p>
                <p class="right">活动室总数：<span class="green"><em id="count"></em>个</span></p>
            </div>
            <div class="border1px border-radius4 relative mb40px">
                <table class="layui-hide" id="test" lay-filter="test"></table>
            </div>
        </div>
    </div>
</div>
<script src="../static/bm/js/jquery-2.1.3.min.js"></script>
<script src="../static/bm/layui/layui.js" charset="utf-8"></script>
<script>

    $(function () {
        getData();

        $("#serchBtn").click(function () {
            getData();
        })
    });


    //左侧菜单栏
    function getData() {
        layui.use(['element', 'table', 'layer'], function () {
            var element = layui.element;
            var table = layui.table;
            var layer = layui.layer;
            var param = $("#param").val();
            //第一个实例
            table.render({
                elem: '#test'
                //,url: '/demo/table/user/'
                , url: "../activity/getActivityList"
                , where: {param: param, type: 1}
                // , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                // , toolbar: true
                // , defaultToolbar: []
                , request: {
                    pageName: 'currentPage' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                //,count: 10  //数据总数，从服务端得到
                //,data: listData
                , page: true //开启分页
                , limit: 10 //每页显示的条数
                //,limits:[3,4,5]
                , groups: 9 //连续页码个数
                , parseData: function (res) {
                    console.log(res);
                    return {
                        "code": res.code,
                        "data": res.data.records,
                        "count": res.data.total,
                        "limit": res.data.size,
                    };
                }
                ,
                cols: [
                    [ //表头
                        {
                            field: 'name',
                            title: '活动室名称',
                        }, {
                        field: 'type',
                        title: '活动室类型',
                    }, {
                        field: 'address',
                        title: '活动室地址',
                    }, {
                        field: 'contacts',
                        title: '联系人',
                    }, {
                        field: 'phone',
                        title: '手机号',
                    }, {
                        field: 'cardId',
                        title: '设备号',
                    }, {
                        field: 'operation',
                        title: '操作',
                        style: 'color:#1C9399',
                        fixed: 'right',
                        templet: function (res) {
                            if (isCURD) {
                                return "<div class='table-list-btn cursor'><span onclick=\"getDetailsById('" + res.id + "')\">查看</span>|" +
                                    "<span class='cursor' onclick=\"editById('" + res.id + "')\">编辑</span>|" +
                                    "<span class='cursor' onclick=\"deleteById('" + res.id + "')\">删除</span></div>"
                            } else {
                                return "<div class='table-list-btn cursor'><span onclick=\"getDetailsById('" + res.id + "')\">查看</span>|" +
                                    "<span  style=\"color: #eee; class=\"cursor\">编辑</span>|" +
                                    "<span  style=\"color: #eee; class=\"cursor\">删除</span></div>"
                            }

                        }
                    }
                    ]
                ], done: function (res, curr, count) {
                    $("#count").text(count);
                }
            });

        });
    }


    function toAdd() {
        window.location.href = "../activity/toActivityAdd"
    }

    function getDetailsById(id) {
        window.location.href = "../activity/toActivityDetails?id=" + id;
    }

    function editById(id) {
        window.location.href = "../activity/toActivityAdd?id=" + id;
    }

    function deleteById(id) {
        var data = {id: id};
        layer.confirm('是否删除该信息', {
            btn: ['确定', '取消']
        }, function () {
            layer.closeAll();
            $.ajax({
                url: "../activity/deleteActivityById",
                type: "delete",
                async: false,
                dataType: "json",
                data: data,
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg);
                        getData();
                    } else {
                        layer.msg(result.msg);
                    }
                }
            })
        });
    }
</script>
</body>

</html>
